﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using DynaSpace.Menu;

namespace DynaSpace.Game1
{
	/// <summary>
	/// Plugin zajišťující hlavní menu
	/// </summary>
	internal class MenuComponent : DynaComponentBase 
	{
		MenuContainer menu;
		MenuContainer menuHelp;

		public MenuComponent(DynaGame game)
			: base(game)
		{
		}

		public override void Initialize()
		{
			base.Initialize();

			menu = new DynaSpace.Menu.MenuContainer("main",true);
			menu.Items.Add(new DynaSpace.Menu.MenuHeader("Hlavní menu"));
			menu.Items.Add(new DynaSpace.Menu.MenuLabel("Vítejte v DynaSpace hře Game1"));
			menu.Items.Add(new DynaSpace.Menu.MenuButton("Začít hru", new Action<MenuButton>((mb) => menu.Visible = false)));
			menu.Items.Add(new DynaSpace.Menu.MenuButton("Nápověda", new Action<MenuButton>((mb) => menuHelp.Visible = true)));
			menu.Items.Add(new DynaSpace.Menu.MenuButton("Konec", new Action<MenuButton>((mb) => DynaGame.Game.Exit())));
			menu.CenterRight(5);
			menu.AutoHeight = false;
			Game.Menus.Items.AddLast(menu);

			menuHelp = new DynaSpace.Menu.MenuContainer("main.help",false);
			menuHelp.Width = 400;
			menuHelp.Items.Add(new DynaSpace.Menu.MenuHeader("Nápověda"));
			menuHelp.Items.Add(new DynaSpace.Menu.MenuLabel("DynaSpace je otevřený projekt založený na XNA 3.0"));
			menuHelp.Items.Add(new DynaSpace.Menu.MenuLabel("Autorem je Tomáš Jecha z portálu VbNet.cz"));
			menuHelp.Items.Add(new DynaSpace.Menu.MenuButton("« Zpět", new Action<MenuButton>((mb) => menuHelp.Visible = false)));
			menuHelp.Center();
			Game.Menus.Items.AddLast(menuHelp);

		}

		public override void Update(GameTime gameTime)
		{
			base.Update(gameTime);

			if (!Game.Menus.MenuFocus
				&& Game.IsKeyPressedOnce(PlayerIndex.One, DynaSpace.Input.PlayerButton.Action))
			{
				menu.Visible = true;
			}
		}

		protected override void LoadContent()
		{
			this.UpdateOrder = 10;
			base.LoadContent();
		}

	}
}
